package com.leo.biz.service.register;

import com.leo.biz.constants.ConfigCentre;
import com.leo.biz.service.zookeeper.ZkClient;
import org.springframework.stereotype.Service;

/**
 * Created by leo on 2016/11/9.
 */
@Service
public class ServiceRegister {

    public void init()
    {
        try {
            ZkClient.register(ConfigCentre.getServiceCfgPath(),getProjectName(),getProjectName().getBytes());
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
    }

    public String getProjectName()
    {
        String ret=System.getProperty("user.dir");
        int pos=ret.lastIndexOf("\\");
        if(pos<0)
        {
            pos=ret.lastIndexOf("/");
        }
        return ret.substring(pos+1);
    }
}
